package org.example.day20240903文件操作;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Main3 {
    public static void main(String[] args) throws IOException {
        FileReader fileReader = new FileReader("input.txt");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line = bufferedReader.readLine();
        int sum = 0;
        Map<String,Integer> student = new HashMap<>();
        for(int i=0; i<Integer.parseInt(line); i++){
            String msg = bufferedReader.readLine();
            String[] strArr = msg.split(" ");
            int money = 0;
            if(strArr[3].equals("Y") && Integer.parseInt(strArr[2]) > 80){
                money += 850;
            }
            if(strArr[4].equals("Y") && Integer.parseInt(strArr[1]) > 85){
                money += 1000;
            }
            if(Integer.parseInt(strArr[1]) > 90){
                money += 2000;
            }
            if(Integer.parseInt(strArr[1]) > 85 && Integer.parseInt(strArr[2]) > 80){
                money += 4000;
            }
            if(Integer.parseInt(strArr[1]) > 80 && Integer.parseInt(strArr[5]) > 0){
                money += 8000;
            }
            sum += money;
            if(money > 0){
                student.put(strArr[0],money);
            }
        }
        String stuMax = "";
        int maxMoney = 0;
        for (Map.Entry<String,Integer> entry : student.entrySet()) {
            if (entry.getValue() > maxMoney) {
                maxMoney = entry.getValue();
                stuMax = entry.getKey();
            }
        }
        FileWriter fileWriter1 = new FileWriter("output.txt");
        BufferedWriter outBufferedWriter = new BufferedWriter(fileWriter1);
        outBufferedWriter.write(stuMax+"\n" +
                        maxMoney +"\n" +
                        sum);
        outBufferedWriter.close();
    }
}
